<template>
	<view>
		<uni-list>
			<block v-for="item in addressList" >
				<uni-swipe-action>
					<uni-swipe-action-item :right-options="options" @click="bindClick($event, item)">
						<uni-list-item showArrow clickable @click="handleClick(item)">
							<template v-slot:body>
								<view class="slot-box">
									<view class="text-secondary">
										<view class="flex align-center">
											<text class="text-main mr-1">{{item.receiverName}}</text>
											{{item.receiverMobile}}
											<text class="text-main font-weight-bold ml-1" v-if="item.isDefault == 1">[默认]</text>
										</view>
									</view>
									<view class="font-weight-bold mt-1">{{item.provinceName}} {{item.cityName}}  {{item.districtName}}</view>
									<view class="text-muted font-sm mt-1">{{item.detailAddress}}</view>
								</view>
							</template>
						</uni-list-item>
					</uni-swipe-action-item>
				</uni-swipe-action>
			</block>
		</uni-list>
	</view>
</template>

<script setup>
	import { ref } from "vue";
	import { onShow } from "@dcloudio/uni-app";
	import { delDeliveryAddress } from "@/api/address/index.js"
	const emit = defineEmits(["handleClick"]);
	const props = defineProps({
		addressList: {
			type: Array,
			default: () => []
		}
	});
	
	const  options = [
	    {
	        text: '修改',
	        style: {
	            backgroundColor: '#007aff'
	        }
	    }, {
	        text: '删除',
	        style: {
	            backgroundColor: '#dd524d'
	        }
	    }
	  ]
	
	onShow(() => {
		console.log("onShow==>",props.addressList);
	});
	
	const handleClick = (item)=>{
		emit("handleClick", item)
	}
	
	const bindClick = async (e, item)=>{
		if(e.content.text == "修改"){
			let obj = JSON.stringify(item)
			uni.navigateTo({
				url:"/pages/addAddress/addAddress?data="+obj
			})
		}
		if(e.content.text == "删除"){
			uni.showModal({
				content:"是否删除该收货地址?",
				success: async (res)=> {
					if(res.confirm){
						await delDeliveryAddress({id:item.id});
						getUserAddress();
					}
				}
			})
		}
	}
</script>

<style>

</style>